/*
 * This file is part of aKoustiK.

 * aKoustiK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * aKoustiK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with aKoustiK.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MEDIASEEKER_H
#define MEDIASEEKER_H

#include <item.h>

#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QUrl>

/**
  Class responsible for scanning folders for audio items and resolving their meta data.

  It's using QThreadPool to scan in background.
  When scan complete - beforePlaylistAppend(int,int) signal will be emited, then
  all found items will be appended to playlist, then afterPlaylistAppend() signal
  will be emited.

  Object of this class will schedule itself for deletion as soon as it's job done.
  */
class MediaSeeker : public QObject {
    Q_OBJECT

public:
    /** Constructing with list of target Urls. */
    MediaSeeker(const QList<QUrl>& targetUrls);
    ~MediaSeeker();

    /** Check if urls list is not empty. If it is - return.
      Otherwise background thread will be started and
      exec() invoked to do the job in background thread. */
    void start();
    /** Synchronious method to do the job. It will be started from
      background thread and will do all the job, including deleting self. */
    void exec();

private:
    /** Input list of urls to scan. */
    QList<QUrl> urls;
    /** Resulting list of items. */
    QList<Item*> items;

signals:
    /** Signal invoked just before appending any items to playlist.
      Used by UI to update any views. */
    void beforePlaylistAppend(int index, int size);
    /** Signal that notifies that appending is done.
      Used by UI to update any views. */
    void afterPlaylistAppend();

};

#endif
